import request from '@/request/http'
const homeAPI = Object.freeze({
  getIndexInfo: '/index/index',
  getHotRecommend: '/index/hot',
  getNewArticle: '/index/new',
  addArticle: '/user/addArticle',
  getCateList: '/index/list',
  getArticleDetial: '/index/show',
  userDataHandle: '/user/userDataHandle'
})

export const getIndexInfo = function () {
  return request({
    method: 'GET',
    url: homeAPI.getIndexInfo
  })
}
export const getHotRecommend = function () {
  return request({
    method: 'GET',
    url: homeAPI.getHotRecommend
  })
}
export const getNewArticle = function (params) {
  return request({
    method: 'GET',
    url: homeAPI.getNewArticle,
    params
  })
}
export const addArticle = function (data) {
  return request({
    method: 'POST',
    url: homeAPI.addArticle,
    data
  })
}
export const getCateList = function (cateid, page) {
  return request({
    method: 'GET',
    url: homeAPI.getCateList,
    params: {
      limit: 10,
      page,
      cateid
    }
  })
}

export const getArticleDetial = function (id) {
  return request({
    method: 'GET',
    url: homeAPI.getArticleDetial,
    params: {
      id
    }
  })
}
export const userDataHandle = function (type, articleid, action) {
  return request({
    method: 'GET',
    url: homeAPI.userDataHandle,
    params: {
      type,
      article_id: articleid,
      action
    }
  })
}
